import { createStore, applyMiddleware, compose } from 'redux';
import { routerMiddleware } from 'react-router-redux';
import Reducers from '../reducers';

// import createLogger from 'redux-logger';
// import thunk from 'redux-thunk';
var thunk = require('redux-thunk').default
export default function storeCreater(history, initialState){ // 系统初始化state

  const middlewares = [
    thunk, // 异步操作中间件
    routerMiddleware(history), // 路由中间件
    // createLogger(), // 打印state
  ];

  const store = createStore(
    Reducers,
    initialState,
    compose(
      applyMiddleware(...middlewares)
    )
  );

  if (module.hot) {
    // 启用Webpack热模块替换reducers
    module.hot.accept('../reducers', () => {
      const nextReducer = require('../reducers/index').default;
      store.replaceReducer(nextReducer);
    });
  }

  return store;
};
